package leetcode.Y2024M7;

/**
 * S211
 * 需要递归，不想看了，把Trie题完成就行
 */
public class WordDictionary {
    class WDTree {
        private boolean end;
        WDTree[] next;

        public WDTree() {
            this.end = false;
            next = new WDTree[26];
        }
    }

    public WDTree root;

    public WordDictionary() {
        root = new WDTree();
    }

    public void addWord(String word) {
        WDTree node = root;
        for (char c : word.toCharArray()) {
            int index = c - 'a';
            if (node.next[index] == null) {
                node.next[index] = new WDTree();
            }
            node = node.next[index];
        }
        node.end = true;
    }

    public boolean search(String word) {
        WDTree node = root;
        for (char c : word.toCharArray()) {
            int index = c - 'a';
            if (c == '.') {
                // 遍历这里的所有子树，如果可以找到下一级就行

            }else {
                if (node.next[index] == null) return false;
            }

            node = node.next[index];
        }
        return node.end;
    }
}
